﻿using Cache;
using DtoFw;
using DtoFw.Base;
using DtoFw.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 预警接口
    /// </summary>
    [Route("api/warn")]
    [AllowAnonymous]
    public class WarnController : BaseController
    {
        private readonly WarnService _warnService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="warnService"></param>
        public WarnController(WarnService warnService)
        {
            this._warnService = warnService;
        }

        /// <summary>
        /// 查询未绑定的数据
        /// </summary>
        /// <returns></returns>
        [HttpPost("queryWarnBind")]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnBind(WarnBindDto dto)
        {
            return _warnService.QueryWarnBind(dto);
        }

        /// <summary>
        /// 查询异常出库数据
        /// </summary>
        /// <returns></returns>
        [HttpPost("queryWarnCheckOut")]
        public BaseGenericResult<Pager<WarnCheckoutDto>> QueryWarnCheckOut(WarnCheckoutDto dto)
        {
            return _warnService.QueryWarnCheckOut(dto);
        }


        /// <summary>
        /// 处理未绑定数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("handleWarnBind/{hour}")]
        public BaseGenericResult<bool> HandleWarnBind(int hour)
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            //处理多少小时之前的数据
            return _warnService.HandleWarnBind(hour, _user);
        }

        /// <summary>
        /// 异常出库
        /// </summary>
        /// <returns></returns>
        [HttpGet("home")]
        public BaseGenericResult<WarnCheckoutRespDto> GetWarnCheckout() 
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _warnService.GetWarnCheckout(_user);
        }

        /// <summary>
        /// 首页环境传感器状态
        /// </summary>
        /// <returns></returns>
        [HttpGet("home/envi")]
        public BaseGenericResult<EnvironmentDto> GetHomeEnvironmentDto()
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _warnService.GetEnvironment(_user);
        }

        /// <summary>
        /// 首页环境传感器状态
        /// </summary>
        /// <returns></returns>
        [HttpGet("home/envilistbyty")]
        public BaseGenericResult<List<object>> GetEnviListByTy(string ty)
        {
            var _user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _warnService.GetEnviListByTy(_user, ty);
        }
    }
}
